/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kungkhies.common.services.kungkhie.validate.xml.knodes;

import com.kungkhies.common.services.kungkhie.parse.KungkhieParseService;
import com.kungkhies.common.services.kungkhie.validate.xml.KungkhieXmlValidateServiceImpl;
import com.kungkhies.common.services.kungkhie.validate.xml.KungkhieXmlValidateServiceImpl;
import com.kungkhies.xml.schema.kungkhie.ActivityType;
import com.kungkhies.xml.schema.kungkhie.AssessmentType;
import com.kungkhies.xml.schema.kungkhie.KNodeListType;
import com.kungkhies.xml.schema.kungkhie.KNodeType;
import com.kungkhies.xml.schema.kungkhie.KungkhieDocument;
import com.kungkhies.xml.schema.kungkhie.SweetieListType;
import com.kungkhies.xml.schema.kungkhie.SweetieType;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author clayton
 */
public class KungkhieXmlValidateServiceImplTest_KNodeList
{
    public KungkhieXmlValidateServiceImplTest_KNodeList()
    {
    }
    
    @BeforeClass
    public static void setUpClass()
    {
    }
    
    @AfterClass
    public static void tearDownClass()
    {
    }
    
    @Before
    public void setUp()
    {
    }
    
    @After
    public void tearDown()
    {
    }

    

    /**
     * Test of validateKungkhieType method, of class KungkhieXmlValidateServiceImpl.
     */
    @Test
    public void testValidateKungkhieKNodeList_Cardinality() throws Exception
    {
        System.out.println("validateKungkhieKNodeList");
        KungkhieDocument kungkhieDocument = null;
        KungkhieXmlValidateServiceImpl instance = new KungkhieXmlValidateServiceImpl();
        String pathToFile = "resources/example-kungkhie-1.xml";
        String filename = "validateContent.txt";
        kungkhieDocument = instance.createKungkhieDocument(pathToFile, filename);
        
        int expected = 3;
        
        int actual = kungkhieDocument.getKungkhie().getKNodeList().sizeOfKNodeArray();
        
        assertEquals(expected, actual);
    }
    
    /**
     * Test of validateKungkhieType method, of class KungkhieXmlValidateServiceImpl.
     */
    @Test
    public void testValidateKungkhieKNodeList_Attributes() throws Exception
    {
        System.out.println("validateKungkhieKNodeList_Attributes");
        KungkhieDocument kungkhieDocument = null;
        KungkhieXmlValidateServiceImpl instance = new KungkhieXmlValidateServiceImpl();
        String pathToFile = "resources/example-kungkhie-1.xml";
        String filename = "validateContent.txt";
        kungkhieDocument = instance.createKungkhieDocument(pathToFile, filename);
        
        KNodeListType kNodeList = kungkhieDocument.getKungkhie().getKNodeList();
        
        KNodeType[] kNodeArray = kNodeList.getKNodeArray();
        
        String kNodeID = kNodeArray[0].getKNodeID();
        String kNodeDisplayName = kNodeArray[0].getDisplayName();
        String kNodeType = kNodeArray[0].getTypeString();
        
        String kNodeIDExpected = "node-1";
        String kNodeDisplayNameExpected = "node1_display_name";
        String kNodeTypeExpected = "hole";
        
        assertEquals(kNodeIDExpected, kNodeID);
        assertEquals(kNodeDisplayNameExpected, kNodeDisplayName);
        assertEquals(kNodeTypeExpected, kNodeType);
        
        kNodeID = kNodeArray[1].getKNodeID();
        kNodeDisplayName = kNodeArray[1].getDisplayName();
        kNodeType = kNodeArray[1].getTypeString();
        
        kNodeIDExpected = "node-2";
        kNodeDisplayNameExpected = "node2_display_name";
        kNodeTypeExpected = "activity";
        
        assertEquals(kNodeIDExpected, kNodeID);
        assertEquals(kNodeDisplayNameExpected, kNodeDisplayName);
        assertEquals(kNodeTypeExpected, kNodeType);
        
        kNodeID = kNodeArray[2].getKNodeID();
        kNodeDisplayName = kNodeArray[2].getDisplayName();
        kNodeType = kNodeArray[2].getTypeString();
        
        kNodeIDExpected = "node-3";
        kNodeDisplayNameExpected = "node3_display_name";
        kNodeTypeExpected = "hole";
        
        assertEquals(kNodeIDExpected, kNodeID);
        assertEquals(kNodeDisplayNameExpected, kNodeDisplayName);
        assertEquals(kNodeTypeExpected, kNodeType);
        
    }
    
    /**
     * Test of validateKungkhieType method, of class KungkhieXmlValidateServiceImpl.
     */
    @Test
    public void testValidateKungkhieKNodeList_Activity() throws Exception
    {
        System.out.println("validateKungkhieKNodeList_Activity");
        KungkhieDocument kungkhieDocument = null;
        KungkhieXmlValidateServiceImpl instance = new KungkhieXmlValidateServiceImpl();
        String pathToFile = "resources/example-kungkhie-1.xml";
        String filename = "validateContent.txt";
        kungkhieDocument = instance.createKungkhieDocument(pathToFile, filename);
        
        KNodeListType kNodeList = kungkhieDocument.getKungkhie().getKNodeList();
        
        KNodeType[] kNodeArray = kNodeList.getKNodeArray();
        
        ActivityType[] activityArray = kNodeArray[1].getActivityArray();
        
        ActivityType activity = activityArray[0];
        
        String activityDisplayName = activity.getDisplayName();
        String urlString = activity.getUrl();
        String activityDescription = activity.getActivityDescription();
        boolean activityAssIncluded = activity.getAssIncluded();
        
        String activityDisplayNameExpected = "activity_display_name";
        String urlStringExpected = "http://www.activity.url/activity1.htm";
        String activityDescriptionExpected = "activity1_description";
        boolean activityAssIncludedExpected = false;
        
        assertEquals(activityDisplayNameExpected, activityDisplayName);
        assertEquals(urlStringExpected, urlString);
        assertEquals(activityDescriptionExpected, activityDescription);
        assertEquals(activityAssIncludedExpected, activityAssIncluded);
        
        
    }
    
     /**
     * Test of validateKungkhieType method, of class KungkhieXmlValidateServiceImpl.
     */
    @Test
    public void testValidateKungkhieKNodeList_Assessment() throws Exception
    {
        System.out.println("validateKungkhieK_Assessment");
        KungkhieDocument kungkhieDocument = null;
        KungkhieXmlValidateServiceImpl instance = new KungkhieXmlValidateServiceImpl();
        String pathToFile = "resources/example-kungkhie-1.xml";
        String filename = "validateContent.txt";
        kungkhieDocument = instance.createKungkhieDocument(pathToFile, filename);
        
        AssessmentType assessment = kungkhieDocument.getKungkhie().getKNodeList().getKNodeArray(1).getActivityArray(0).getAssessment();
        
        String assessmentDisplayName = assessment.getDisplayName();
        String assessmentUrl = assessment.getUrl();
        String assessmentDescription = assessment.getDescription();
        boolean assessmentAnswersIncluded = assessment.getAnswersIncluded();
        float assessmentTimeEstimate = assessment.getTimeEstimate();
        
        String assessmentDisplayNameExpected = "activity_display_name";
        String assessmentUrlExpected = "http://www.assessments.ac.uk/assessment1.htm";
        String assessmentDescriptionExpected = "assessment_description";
        boolean assessmentAnswersIncludedExpected = true;
        float assessmentTimeEstimateExpected = 0.45f;
    }
    
    /**
     * Test of validateKungkhieType method, of class KungkhieXmlValidateServiceImpl.
     */
    @Test
    public void testValidateKungkhieKNodeList_Assessment_Sweeties() throws Exception
    {
        System.out.println("validateKungkhieK_Assessment");
        KungkhieDocument kungkhieDocument = null;
        KungkhieXmlValidateServiceImpl instance = new KungkhieXmlValidateServiceImpl();
        String pathToFile = "resources/example-kungkhie-1.xml";
        String filename = "validateContent.txt";
        kungkhieDocument = instance.createKungkhieDocument(pathToFile, filename);
        
        ActivityType activity = kungkhieDocument.getKungkhie().getKNodeList().getKNodeArray(1).getActivityArray(0);
        
        SweetieListType sweetieList = activity.getSweetieList();
        
        SweetieType[] sweetieArray = sweetieList.getSweetieArray();
        
        int sweetieCardinality = sweetieArray.length;
        
        int sweetieArrayCardinalityExpected = 3;
        
        assertEquals(sweetieArrayCardinalityExpected, sweetieCardinality);
        
        
        
        String sweetieDisplayName = sweetieArray[0].getSweetieDisplayName();
        String sweetieDescription = sweetieArray[0].getSweetieDescription();
        String sweetieUrl = sweetieArray[0].getSweetieUrl();
        
        String sweetieDisplayNameExpected = "sweetie1_display_name";
        String sweetieUrlExpected = "http://www.sweeties.ac.uk/sweetie1.htm";
        String sweetieDescriptionExpected = "sweetie1_description"; 
        
        assertEquals(sweetieDisplayNameExpected, sweetieDisplayName);
        assertEquals(sweetieDescriptionExpected, sweetieDescription);
        assertEquals(sweetieUrlExpected, sweetieUrlExpected);
        
        URL url = null;
        boolean isValidUrl = true;
        
        try
        {
            url = new URL(sweetieUrl);
        }
        catch (MalformedURLException malformedURLException)
        {
            isValidUrl = false;
        }
        
        assertEquals(true, isValidUrl);
        
        sweetieDisplayName = sweetieArray[1].getSweetieDisplayName();
        sweetieDescription = sweetieArray[1].getSweetieDescription();
        sweetieUrl = sweetieArray[1].getSweetieUrl();
        
        sweetieDisplayNameExpected = "sweetie2_display_name";
        sweetieUrlExpected = "http://www.sweeties.ac.uk/sweetie2.htm";
        sweetieDescriptionExpected = "sweetie2_description"; 
        
        isValidUrl = true;
        
        try
        {
            url = new URL(sweetieUrl);
        }
        catch (MalformedURLException malformedURLException)
        {
            isValidUrl = false;
        }
        
        assertEquals(true, isValidUrl);
        
        assertEquals(sweetieDisplayNameExpected, sweetieDisplayName);
        assertEquals(sweetieDescriptionExpected, sweetieDescription);
        assertEquals(sweetieUrlExpected, sweetieUrlExpected);
        
        sweetieDisplayName = sweetieArray[2].getSweetieDisplayName();
        sweetieDescription = sweetieArray[2].getSweetieDescription();
        sweetieUrl = sweetieArray[2].getSweetieUrl();
        
        sweetieDisplayNameExpected = "sweetie3_display_name";
        sweetieUrlExpected = "http://www.sweeties.ac.uk/sweetie3.htm";
        sweetieDescriptionExpected = "sweetie3_description"; 
        
        assertEquals(sweetieDisplayNameExpected, sweetieDisplayName);
        assertEquals(sweetieDescriptionExpected, sweetieDescription);
        assertEquals(sweetieUrlExpected, sweetieUrlExpected);
        
        isValidUrl = true;
        
        try
        {
            url = new URL(sweetieUrl);
        }
        catch (MalformedURLException malformedURLException)
        {
            isValidUrl = false;
        }
        
        assertEquals(true, isValidUrl);
       
    }

    
}
